from typing import Optional
from pathlib import Path

from app.config import settings

# Import both LLM implementations
from app.llm.openai_llm import optimize_with_llm as openai_optimize, describe_image_with_llm as openai_describe
from app.llm.bedrock_llm import optimize_with_bedrock_llm as bedrock_optimize, describe_image_with_bedrock_llm as bedrock_describe


async def optimize_with_llm(file_path: Path, language: Optional[str] = None) -> str:
    """
    Optimize markdown document using the configured LLM provider.
    
    Args:
        file_path: Path to the markdown file to optimize
        language: Target language for optimization
        
    Returns:
        Optimized document content as string
        
    Raises:
        Exception: If LLM optimization fails
    """
    if settings.llm_provider == "bedrock":
        return await bedrock_optimize(file_path, language)
    else:
        return await openai_optimize(file_path, language)


async def describe_image_with_llm(image_path: Path, language: Optional[str] = None) -> str:
    """
    Describe image content using the configured LLM provider.
    
    Args:
        image_path: Path to the image file to describe
        language: Target language for description
        
    Returns:
        Image description as string
        
    Raises:
        Exception: If LLM image description fails
    """
    if settings.llm_provider == "bedrock":
        return await bedrock_describe(image_path, language)
    else:
        return await openai_describe(image_path, language)